What is wrong with the following code segment?
Point myPoint = new Point(); // construct a point at x=0, y=0 myPoint.move(); // move the point to a new location
The second statement calls the move()
method of the Point
,
but does not supply information about where to move the point.
In this case, saying what method to run is not enough.
The method needs information about what it is to do.
When you look at the description of class Point
the move()
method
is described as follows:
// change (x,y) of a point object public void move(int x, int y);
This description says that the method requires two parameters:
int
. It will become the new value for x.
int
. It will become the new value for y.
Dot notation is used to specify which object, and what method of that object to run. The parameter list of the method supplies the method with data.
Here are some examples:
Point pointA = new Point(); pointA.move( 45, 82 ); int col = 87; int row = 55; pointA.move( col, row );
You can put expressions into parameter lists if the expression evaluates to the correct type. The expressions are evaluated before the method starts running.
pointA.move( 24-12, 30*3 + 5 ); pointA.move( col-4, row*2 + 34 );
What is the location of pointA
after the following:
pointA.move( 24-12, 30*3 + 5 );